<?php
/**
 * Author: hezhizheng
 * Created by PhpStorm.
 */

namespace App\Models\Version;

use App\Services\Utils\Bosable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;


class Version extends Model
{
    use Bosable;
    protected $bos_url_prefix = 'version/apk/';

    const ANDROID_BEAUTY_MIRROR = 'ANDROID_BEAUTY_MIRROR';
    const IOS_BEAUTY_MIRROR = 'IOS_BEAUTY_MIRROR';
    const UNITY_BEAUTY_MIRROR = 'UNITY_BEAUTY_MIRROR';

    protected $table = 'versions';
    protected $guarded = [];


    /**
     * @param $file
     * @throws \Exception
     */
    public function setSoftwareUrlAttribute($file)
    {

        if (is_file($file)) {
            $this->attributes['software_url'] = $this->uploadFile($file, $this->bos_url_prefix, false);
        }else{
            $this->attributes['software_url'] = $file;
        }
    }

    /**
     * @return mixed|null
     */
    public function getSoftwareUrlAttribute()
    {
        if (!$this->attributes['software_url']) return null;

        return $this->getStaticUrl($this->attributes['software_url']);
    }
}